import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:znmm/config/app_color.dart';
import 'rogions_item.dart';
//import '../../message_management/template_edti/template_edit_mag.dart';
import '../mag/edti_temp_mag.dart';

class SelLanguageView extends StatefulWidget {
  final Function(String) onLanguageSelected; // 回调参数

  const SelLanguageView({super.key, required this.onLanguageSelected});

  @override
  State<SelLanguageView> createState() => _SelLanguageViewState();
}

class _SelLanguageViewState extends State<SelLanguageView> {
  //选中的语言
  String _selIdStr = 'en';

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: AppColor.white,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.w),
          topRight: Radius.circular(20.w),
        ),
      ),
      child: Column(
        children: [
          Container(
            height: 50.w,
            width: double.infinity,
            alignment: Alignment.center,
            child: Text(
              '选择语言',
              style: TextStyle(
                color: AppColor.black,
                fontSize: 16.sp,
              ),
            ),
          ),
          Expanded(
            child: ListView.builder(
              itemCount: EdtiTempMag().languageList.length,
              itemBuilder: (ctx, index) {
                return GestureDetector(
                  onTap: () {
                    // setState(() {

                    // });

                    Get.back();
                    _selIdStr = EdtiTempMag().languageList[index]['id'];
                    widget.onLanguageSelected(_selIdStr);
                  },
                  child: RogionsItem(
                    ///获取当前语言
                    title: 1 == 1
                        ? EdtiTempMag().languageList[index]['en']
                        : EdtiTempMag().languageList[index]['zh'],
                    check: _selIdStr == EdtiTempMag().languageList[index]['id'],
                  ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
